<template>
	<view>
		<u-row customStyle="margin-top: 50rpx;">
			<u-col span="10" offset="1">
				 <u--input
				    :placeholder="name"
				    border="surround"
				    v-model="name" 
				  ></u--input>
			</u-col>
		</u-row>
		
		<u-row   customStyle="margin-top: 50rpx;">
			<u-col span="10" offset="1">
				<u-button type="primary"  @click="save" text="保存"></u-button>
			</u-col>
		</u-row>
		<u-row customStyle="margin-top: 50rpx;" v-if="shopId != userInfo.store_id" >
			<u-col span="10" offset="1">
				<u-button type="error" v-if="!base" @click="del" text="删除店铺"></u-button>
			</u-col>
		</u-row>
	</view>
</template>

<script>
	var ERShoopManage = require('../../../../service/ERShoopManage.js'),
		mERShoopManage;
	var that
	export default {
		data() {
			return {
				shopId:'',
				shopName:'',
				base:false,
				name:'',
				userInfo:{}
			}
		},
		onLoad(options) {
			that = this
			if(options.base){
				this.base = options.base
			}
			if(options.name){
				this.name = options.name
			}
			console.log(options)
			mERShoopManage = new ERShoopManage(this.mNetTool);
			this.shopId = options.shopId
		},
		mounted() {
			that.userInfo = uni.getStorageSync('userInfo')
			that.shopList = uni.getStorageSync('shopList')
			
		},
		methods: {
			del(){
				let list = that.shopList
				uni.showModal({
					title:'提示',
					content:'确定要删除吗？注意，此过程不可逆！',
					success(e) {
						if(e.confirm){
							let viewShopListItem = uni.getStorageSync('viewShopListItem')
							if(viewShopListItem.id == that.shopId){
								//如果删除当前店铺
								uni.removeStorageSync('viewShopListItem')
								uni.removeStorageSync('shelfList')
							}
							mERShoopManage.del({id:that.shopId},res=>{
								debugger
								uni.navigateBack({
									
								})
							
							})
						}
					}
				})
			},
			save(){
					let list = that.shopList
				this.mNetTool.getAjaxUrlValueBackground('capi/V2/ERShopManage/erShopManage/update',
				{
					id:that.shopId,
					shop_name:that.name
				},res => {
					if(res.success){
						let viewShopListItem = uni.getStorageSync('viewShopListItem')
						if(viewShopListItem.id == that.shopId){
							//如果删除当前店铺
						 viewShopListItem.shop_name= that.name
						 uni.setStorageSync('viewShopListItem',viewShopListItem)
						}
						uni.$u.toast('修改成功')
						 uni.navigateBack({
						 	
						 })
					}else {
						uni.$u.toast('修改失败')
					}
				})
				
			}
		}
	}
</script>

<style>

</style>
